// 引入两个模块
import Vue from 'vue'
import Vuex from 'vuex'

// 使用Vue
Vue.use(Vuex)

const state = {
  username: ''
}
const mutations = {
  setUserName (state, name) {
    state.username = name
    localStorage.setItem('username', name)
  }
}
const actions = {
  setActUserName ({commit}, name) {
    commit('setUserName', name)
  }
}
const getters = {
  getActUserName () {
    return localStorage.getItem('username')
  }
}

export default new Vuex.Store({
  state,
  getters,
  actions,
  mutations
})
